<?php

class adminMAccount extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {
            redirect('user_login/user', 'refresh');
        }

        $this->load->model('maskapai_account');
        $this->load->model('user_role');
        $this->load->model('airline');
        $this->load->library('user_id');
        $this->load->helper('user_helper');

        if ($this->user_id->cek() == 0) {
            redirect('user_login/user', 'refresh');
        }
    }

    function index() {
        $data['id'] = $this->user_id->id();
        $data['i'] = 1;
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['rows'] = $this->maskapai_account->index();
        $data['content'] = 'admin_Maccount/index';
        $this->load->view('template/user', $data);
    }

    function add() {
        $data['id'] = $this->user_id->id();
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['maskapai'] = $this->airline->get_array();
        
        $data['content'] = 'admin_Maccount/new';
        $this->load->view('template/user', $data);
    }

    function edit() {
        $data['id'] = $this->user_id->id();
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['maskapai'] = $this->airline->get_array();
        
        $id = $this->uri->segment(3);
        $data['rows'] = $this->maskapai_account->edit($id);
        
        $data['content'] = 'admin_Maccount/edit';
        $this->load->view('template/user', $data);
        
    }
    
    function create() {
        $maskapai = $this->input->post('id_maskapai');
        $link = $this->input->post('link');
        $body = $this->input->post('body');
        $date = date('Y-m-d');
        $this->maskapai_account->create($maskapai, $body, $link, $date);
    }
    
    function update() {
        $id = $this->input->post('id');
        $maskapai = $this->input->post('id_maskapai');
        $link = $this->input->post('link');
        $body = $this->input->post('body');
        $this->maskapai_account->update($id, $maskapai, $body, $link);
    }
    
    function delete(){
        $id = $this->uri->segment(3);
        $this->maskapai_account->delete($id);
    }

    function id() {
        $session_data = $this->session->userdata('logged_in');
        return $session_data['id'];
    }

}

?>
